package sLinkedList;

public class SLinkedList<E> {
	protected Node<E> head; // head node of the list
	protected int size; // number of nodes in the list

	/** Default constructor that creates an empty list */
	public SLinkedList() {
		head = null;
		size = 0;
	}

	public void addFirst(E e) {
		Node<E> n = new Node<E>();
		n.setElement(e);
		n.setNext(head);
		head = n;
		size++;
	}

	public void addLast(E e) {
		Node<E> n = new Node<E>();
		n.setElement(e);
		if (head == null) {
			head = n;
		}
		else {
			Node<E> curr = head;
			for (int i = 1; i < size; i++) {
				curr = curr.getNext();
			}
			curr.setNext(n);
		}
		size++;
	}

	public E removeFirst() {
		if (head == null) {
			System.out.println("Inutile, la lista e' vuota");
			return null;
		}
		Node<E> temp = head;
		head = head.getNext();
		temp.setNext(null);
		size--;
		return temp.getElement();
	}

	public int getSize() {
		return size;
	}

	public E getHead() {
		if (head == null) {
			System.out.println("Inutile, la lista e' vuota");
			return null;
		}
		return head.getElement();
	}

}
